"""
车辆数据管理模块
包含不同价格区间和年份的车辆数据
"""

# 所有车辆数据
ALL_CARS = [
    # 5万内经济型车
    {
        "brand": "比亚迪",
        "model": "F3",
        "price": "4.8万",
        "year": "2020",
        "mileage": "3.5万公里",
        "features": ["经济实惠", "油耗低", "空间够用"],
        "condition": "车况良好"
    },
    {
        "brand": "吉利",
        "model": "远景",
        "price": "4.5万",
        "year": "2019",
        "mileage": "4.2万公里",
        "features": ["性价比高", "配置丰富", "维修成本低"],
        "condition": "车况良好"
    },
    {
        "brand": "长安",
        "model": "悦翔",
        "price": "4.2万",
        "year": "2018",
        "mileage": "5.1万公里",
        "features": ["经济实用", "空间宽敞", "保养便宜"],
        "condition": "车况良好"
    },
    
    # 5-10万中端车
    {
        "brand": "大众",
        "model": "朗逸",
        "price": "8.5万",
        "year": "2021",
        "mileage": "2.8万公里",
        "features": ["德系品质", "保值率高", "操控性好"],
        "condition": "准新车"
    },
    {
        "brand": "丰田",
        "model": "卡罗拉",
        "price": "9.2万",
        "year": "2020",
        "mileage": "3.2万公里",
        "features": ["日系品质", "可靠性高", "油耗低"],
        "condition": "车况优秀"
    },
    {
        "brand": "本田",
        "model": "思域",
        "price": "9.8万",
        "year": "2021",
        "mileage": "2.5万公里",
        "features": ["运动性能", "外观时尚", "动力充沛"],
        "condition": "准新车"
    },
    
    # 10万以上高端车
    {
        "brand": "大众",
        "model": "帕萨特",
        "price": "15.8万",
        "year": "2022",
        "mileage": "1.5万公里",
        "features": ["商务首选", "空间宽敞", "配置豪华"],
        "condition": "准新车"
    },
    {
        "brand": "丰田",
        "model": "凯美瑞",
        "price": "18.5万",
        "year": "2023",
        "mileage": "0.8万公里",
        "features": ["豪华舒适", "科技配置", "安全性能"],
        "condition": "准新车"
    },
    {
        "brand": "本田",
        "model": "雅阁",
        "price": "16.9万",
        "year": "2022",
        "mileage": "1.2万公里",
        "features": ["豪华商务", "动力强劲", "舒适性好"],
        "condition": "准新车"
    }
]

def get_cars_by_price_range(min_price=0, max_price=30):
    """
    根据价格区间获取车辆数据
    :param min_price: 最低价格（单位：万）
    :param max_price: 最高价格（单位：万）
    :return: 符合条件的车辆列表
    """
    return [
        car for car in ALL_CARS 
        if min_price <= float(car["price"].replace("万", "")) <= max_price
    ]

def get_cars_by_year(year_threshold, is_newer=True):
    """
    根据年份获取车辆数据
    :param year_threshold: 年份阈值
    :param is_newer: True表示获取更新的车，False表示获取更老的车
    :return: 符合条件的车辆列表
    """
    if is_newer:
        return [car for car in ALL_CARS if int(car["year"]) >= year_threshold]
    else:
        return [car for car in ALL_CARS if int(car["year"]) <= year_threshold]

def get_cars_by_brand(brand):
    """
    根据品牌获取车辆数据
    :param brand: 品牌名称
    :return: 符合条件的车辆列表
    """
    return [car for car in ALL_CARS if car["brand"] == brand]

def format_car_info(car):
    """
    格式化车辆信息
    :param car: 车辆数据字典
    :return: 格式化后的字符串
    """
    return f"- {car['brand']} {car['model']} {car['year']}款 {car['price']}（行驶{car['mileage']}）\n" \
           f"  特点：{', '.join(car['features'])}\n" \
           f"  车况：{car['condition']}" 